<?php
ob_start();
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
require_once('calendar/classes/tc_calendar.php');
//include 'operations/connection.php';

$user=$_SESSION['fullname'];


//include "generallibraries/funcs.php";
//$hamsort=" where ac_customer.Activest=1 order by ac_customer.CustomerName desc";
//$sqlCustomer = generalFunctions::listCustomer("ac_customer.CustomerID, ac_customer.CustomerName",$hamsort);
//$mangCustomer=mysql_query($sqlCustomer);

if($_REQUEST['action']){
	$action=$_REQUEST['action'];
	$id=$_REQUEST['idapprovedoc'];
	if($_REQUEST['action']=="editform" || $_REQUEST['action']=="my_declined" || $_REQUEST['action']=="my_sending" || $_REQUEST['action']=="forward"){
		$sql="select Tile,TripDate,Content,Content2,Description,comment,purpose from approvedoc where IDApproveDoc='".$id."'";
		$mangnoidung= mysql_fetch_assoc(mysql_query($sql));
		$fromdate = $mangnoidung['TripDate'];
		if($_REQUEST['action']=="forward")
			$fromdate = date("Y-m-d",time());
		$ftitle=$mangnoidung['Tile'];
		$fdescription=str_replace('<br>',chr(13),$mangnoidung['Description']);
		$fcontent=str_replace('<br>',chr(13),$mangnoidung['Content']);
		$fcomment=$mangnoidung['comment'];
		$fproject=$mangnoidung['Content2'];
		$fpurpose=$mangnoidung['purpose'];
		$querybuy = mysql_query("select * from buying_document where document_id = '$id'");
		if(count($querybuy)>0){
			$listpurchase=array();
			$temp="-1";
			$i=0;
			while ($row = mysql_fetch_array($querybuy))
			{
				if($temp!=$row[company]){
					$temp=$row[company];
					$i=$i+1;
				}
				$listpurchase[]=array(0,$row['name'],$row['company'],$row['amount'],$row['price'],$row['vat'],$row['total'],$i,0);
			}
			$_SESSION['listpurchase']=$listpurchase;
		}else{
			$listpurchase=array();
			$listpurchase[]=array(0,"","",0,0,0,0,1,0);
			$_SESSION['listpurchase']=$listpurchase;
		}
		//attach
		$listattachedit = mysql_query('select id, approveid, filepath, filereal, filename, filetype, filesize, createdate from approve_attach where approveid='.$id);
	}else if($_REQUEST['action']=="newform"){
		$fromdate=date("Y-m-d");
		$ftitle="";
		$fdescription="";
		$fcontent="";
		$fcomment="";
		$fproject="";
		$fpurpose="";
		
		$listpurchase=array();
		$listpurchase[]=array(0,"","",0,0,0,0,1,0);
		
		$_SESSION['listpurchase']=$listpurchase;
	}
}
$url = explode('&', $_SERVER['HTTP_REFERER']);
?>
<!-- attach -->
<script type="text/javascript" src="attach/js/webtoolkit.aim.js"></script>
<script type="text/javascript" src="attach/js/myattach.js"></script>
<link
	href="attach/css/myattach.css" rel="stylesheet" type="text/css" />
<!-- end attach -->
<script type="text/javascript">
function startCallback() {
	// viết code khi click nút upload và bắt đầu upload.
	$('#attachloading').append ('<?=$l_uploading?>');
	return true;
}

</script>
<style type="text/css">
<?php
	$temp=-1;
	$c=0;
	$soct=0;
	foreach ($listpurchase as $purchase){
				
	if($temp!=$purchase[7]){
		$soct++;
		$temp=$purchase[7];
		$c=$purchase[7];
	}}
?>
.content_menu_expand{
	position:absolute; 
	right:-5px;
	top:20px;
	z-index:999;
	background-color: #ffffff;
	-moz-border-radius: 7px;
	-webkit-border-radius: 7px;
	color: #000000;
	width:300px;
	max-height:180px;
	overflow:auto;
}

.passul{padding-left:0; border:1px solid black}
.bgkhac {background: #eee;}
.passul ul{padding:0px}
.passul ul li {color:#474747; font-size:12px;padding: 5px 0;padding-left:5px;list-style: none;text-decoration: none;}
.passul ul li:hover { background: #0A246A;color:white;text-decoration: none;list-style: none;}
</style>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("ul.menu_inside li a").hover(function() {
		$(this).parent().find("ul.subnav").slideDown(0).show();
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp(0);
		});
	}).hover(function() {
		$(this).addClass("subhover");
	}, function(){
		$(this).removeClass("subhover");
	});
	Load(<?=count($listpurchase)+1?>);
	
	
});
function clickmenu(ele,c){
	parents = $(ele).parent().find('#content_menu_expand'+c);
	if ($(parents).is(":hidden")) {
		$(parents).show();
	}
	else {
		$(parents).hide();
	}
	return false;
}

function Load(count){
	var a
	for(var i=1;i<count;i++){
		$("#inputString"+i).autocomplete("operations/rpc.php", {
			selectFirst: true
			
		});
		
		$('#content_menu_expand'+i).hide();
		$(document).click(function() {
			for(var j=1;j<count;j++){
				$("#content_menu_expand"+j).hide();
			}
		});
		$('#content_menu_expand'+i).click(function(e) {
			e.stopPropagation();
		});
		
		$('#menu_expand'+i).click(function(event) {
			var id=event.target.id;
			j=id.split("menu_expand");
			
			if ($('#content_menu_expand'+j[1]).is(":hidden")) {
				$('#content_menu_expand'+j[1]).show();
				for(var k=1;k<count;k++){
					if(k!=j[1])
						$("#content_menu_expand"+k).hide();
				}
			}
			else {
				$('#content_menu_expand'+j[1]).hide();
			}
			return false;
		});
		
	}
	
}
			</script>
<script type="text/javascript">

function focusOnMyInputBox(e,ten){
    var x;
    if(window.event) // IE8 and earlier
    	{
    	x=e.keyCode;
    	}
    else if(e.which) // IE9/Firefox/Chrome/Opera/Safari
    	{
    	x=e.which;
    	}
	if(x==13){
		document.getElementById(ten).focus();
		return false;
	}else{
		return true;
	}
}

function enterTable(e,value,count,co){
    var key = window.event ? e.keyCode : e.which;
    if (key == 13 || key == 8 || key == 46  || key == 37 || key == 39 || key == 45 || co == '0') {
		if(key==13){
			var i = 0;
			var j = 0;
			var listID = new Array();
			for(i = 1; i <= count;i++){
		        listID = listID.concat(["name"+i,"txtNumber"+i,"txtPrice"+i,"txtVat"+i]);	
			}
			if(value == listID[listID.length-1]){	
				document.getElementById("comment").focus();
				return false;			
			}else{
				for (j = 0; j < listID.length; j++){	
					if (listID[j] == value) {	
						if (j == listID.length - 1) {
							return false;
						}
						document.getElementById(listID[j + 1]).focus();
						document.getElementById(listID[j + 1]).select();
						return false; 
					}
				}
			}
			
			return false;
		}else
			return true;	
    } else if ( key < 48 || key > 57 ) {
        return false;
    }
    else return true;
				
}
</script>

<script type="text/javascript">
function clickCustomer(gt,c){
	document.getElementById("inputString"+c).value=gt;
	chCompany(gt,c);
	$('#content_menu_expand'+c).hide();
}
</script>

<script LANGUAGE="JavaScript" type="text/javascript">
function ch(status){
	$("#save").attr('disabled', 'disabled');
	$("#send").attr('disabled', 'disabled');
	$("#delete").attr('disabled', 'disabled');
	if(status!='Delete')
		if(document.f13.title.value==""){
			alert('<?=$l_titlemusthavedate?>');
			document.f13.title.focus();
			$("#save").removeAttr('disabled');
			$("#send").removeAttr('disabled');
			$("#delete").removeAttr('disabled');
			return 0;
		}else{
			
				//if(document.f13.inputString.value==""){
				//	document.f13.inputString.focus();
				//	$("#save").removeAttr('disabled');
				//	$("#send").removeAttr('disabled');
				////	$("#delete").removeAttr('disabled');
				//	return 0;
				//}*/
			
		}
	return 1;
}
</script>
<script type="text/javascript">
function chQuantityPurchase(str,str1)
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("total"+str1).innerHTML=xmlhttp.responseText;
										    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
										    		xmlhttp2=new XMLHttpRequest();
										    	}else{// code for IE6, IE5
										    		xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
										    	}
										    	xmlhttp2.onreadystatechange=function(){
										    										  if (xmlhttp2.readyState==4 && xmlhttp2.status==200){
										    										    	document.getElementById("all").innerHTML=xmlhttp2.responseText;
										    										  }
										    	}
										    	xmlhttp2.open("POST","ajax/chTotalAllPurchases.php?action=chTotal&value="+str+"&id="+str1,true);

										    	xmlhttp2.send();
										  }
									  }
	if(str=='')
		str=0;
	else
		str=parseInt(str,10);
	document.getElementById("txtNumber"+str1).value=str;
	xmlhttp.open("POST","ajax/chQuantityPurchases.php?action=chQuantity&value="+str+"&id="+str1,true);
	xmlhttp.send();


	
}
function chPricePurchase(str,str1)
{
	gt=str;
	if(gt=='')
		gt='0';
	if(gt=='-')
		gt='0';
	if(gt=='-0' || gt=='0-')
		gt='-0';

	var b=gt.split(',');
	if(b.length>1){
		gt='';
		for(i=0;i<b.length;i++){
			gt=gt+b[i];
		}
	}
	
	var a=gt.split('-');
	if(a.length==2){
		am='-';
		gt='';
		for(i=0;i<a.length;i++){
			gt=gt+a[i];
		}
		gt=Number(gt);
		gt=am+gt;
	}else if(a.length==3){
		gt='';
		for(i=0;i<a.length;i++){
			if(a[i]!='-')
				gt=gt+a[i];
		}
		gt=Number(gt);
	}else{
		gt=Number(gt);
	}

	nStr =gt+ '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	gt=x1+x2;

	document.getElementById("txtPrice"+str1).value=gt;
	str=gt;
	
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("vat"+str1).innerHTML=xmlhttp.responseText;
										    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
										    		xmlhttp1=new XMLHttpRequest();
										    	}else{// code for IE6, IE5
										    		xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
										    	}
										    	xmlhttp1.onreadystatechange=function(){
										    										  if (xmlhttp1.readyState==4 && xmlhttp1.status==200){
										    										    	document.getElementById("total"+str1).innerHTML=xmlhttp1.responseText;
										    										    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
										    										    		xmlhttp2=new XMLHttpRequest();
										    										    	}else{// code for IE6, IE5
										    										    		xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
										    										    	}
										    										    	xmlhttp2.onreadystatechange=function(){
										    										    										  if (xmlhttp2.readyState==4 && xmlhttp2.status==200){
										    										    										    	document.getElementById("all").innerHTML=xmlhttp2.responseText;
										    										    										  }
										    										    	}
										    										    	xmlhttp2.open("POST","ajax/chTotalAllPurchases.php?action=chPrice&value="+str+"&id="+str1,true);

										    										    	xmlhttp2.send();
										    										  }
										    	}
										    	xmlhttp1.open("POST","ajax/chQuantityPurchases.php?action=chPrice&value="+str+"&id="+str1,true);

										    	xmlhttp1.send();
										    										    	
										  }
									  }
	
	document.getElementById("txtPrice"+str1).value=str;
	xmlhttp.open("POST","ajax/chPricePurchases.php?action=chPrice&value="+str+"&id="+str1,true);
	xmlhttp.send();


}
function chVatPurchase(str,str1)
{
	gt=str;
	if(gt=='')
		gt='0';
	if(gt=='-')
		gt='0';
	if(gt=='-0' || gt=='0-')
		gt='-0';

	var b=gt.split(',');
	if(b.length>1){
		gt='';
		for(i=0;i<b.length;i++){
			gt=gt+b[i];
		}
	}
	
	var a=gt.split('-');
	if(a.length==2){
		am='-';
		gt='';
		for(i=0;i<a.length;i++){
			gt=gt+a[i];
		}
		gt=Number(gt);
		gt=am+gt;
	}else if(a.length==3){
		gt='';
		for(i=0;i<a.length;i++){
			if(a[i]!='-')
				gt=gt+a[i];
		}
		gt=Number(gt);
	}else{
	
	gt=Number(gt);
	}

	nStr =gt+ '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	gt=x1+x2;

	document.getElementById("txtVat"+str1).value=gt;
	str=gt;
	
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("price"+str1).innerHTML=xmlhttp.responseText;
										    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
										    		xmlhttp1=new XMLHttpRequest();
										    	}else{// code for IE6, IE5
										    		xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
										    	}
										    	xmlhttp1.onreadystatechange=function(){
										    										  if (xmlhttp1.readyState==4 && xmlhttp1.status==200){
										    										    	document.getElementById("total"+str1).innerHTML=xmlhttp1.responseText;
										    										    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
										    										    		xmlhttp2=new XMLHttpRequest();
										    										    	}else{// code for IE6, IE5
										    										    		xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
										    										    	}
										    										    	xmlhttp2.onreadystatechange=function(){
										    										    										  if (xmlhttp2.readyState==4 && xmlhttp2.status==200){
										    										    										    	document.getElementById("all").innerHTML=xmlhttp2.responseText;
										    										    										  }
										    										    	}
										    										    	xmlhttp2.open("POST","ajax/chTotalAllPurchases.php?action=chVat&value="+str+"&id="+str1,true);

										    										    	xmlhttp2.send();
										    										  }
										    	}
										    	xmlhttp1.open("POST","ajax/chQuantityPurchases.php?action=chPrice&value="+str+"&id="+str1,true);

										    	xmlhttp1.send();
										  }
									  }
	document.getElementById("txtVat"+str1).value=str;
	xmlhttp.open("POST","ajax/chVatPurchases.php?action=chVat&value="+str+"&id="+str1,true);
	xmlhttp.send();



	
	
}
function addPurchase(str)
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("company").innerHTML=xmlhttp.responseText;
										    	var a=document.getElementById("count").value+1;
										    	Load(a);
										  }
									  }
	xmlhttp.open("POST","ajax/addCompany.php?action=addPurchase&id="+str,true);
	xmlhttp.send();
}
function checkPurchase(str)
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("company").innerHTML=xmlhttp.responseText;
										    	var a=document.getElementById("count").value+1;
										    	Load(a);
										  }
									  }
	xmlhttp.open("POST","ajax/addCompany.php?action=checkPurchase&id="+str,true);
	xmlhttp.send();
}
function delPurchase(str)
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("company").innerHTML=xmlhttp.responseText;
										    	var a=document.getElementById("count").value+1;
										    	Load(a);
										  }
									  }
	xmlhttp.open("POST","ajax/addCompany.php?action=delPurchase&id="+str,true);
	xmlhttp.send();
}
function addCompany()
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("company").innerHTML=xmlhttp.responseText;
										    	var a=document.getElementById("count").value+1;
										    	Load(a);
										  }
									  }
	xmlhttp.open("POST","ajax/addCompany.php?action=add",true);
	xmlhttp.send();
}

function checkCompany(str)
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("company").innerHTML=xmlhttp.responseText;
										    	var a=document.getElementById("count").value+1;
										    	Load(a);
										  }
									  }
	xmlhttp.open("POST","ajax/addCompany.php?action=check&id="+str,true);
	xmlhttp.send();
}
function delCompany()
{

	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("company").innerHTML=xmlhttp.responseText;
										    	var a=document.getElementById("count").value +1;
										    	Load(a);
										  }
									  }
	xmlhttp.open("POST","ajax/addCompany.php?action=del",true);
	xmlhttp.send();
}
function chCompany(str,str1)
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp2=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp2.onreadystatechange=function(){
										  if (xmlhttp2.readyState==4 && xmlhttp2.status==200){
										    	document.getElementById("all").innerHTML=xmlhttp2.responseText;
										  }
	}
	xmlhttp2.open("POST","ajax/chTotalAllPurchases.php?action=chCompany&value="+encodeURIComponent(str)+"&id="+str1,true);
	xmlhttp2.send();
}
function chItemPurchase(str,str1)
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp2=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp2.onreadystatechange=function(){
										  if (xmlhttp2.readyState==4 && xmlhttp2.status==200){
										    	document.getElementById("all").innerHTML=xmlhttp2.responseText;
										  }
	}
	xmlhttp2.open("POST","ajax/chTotalAllPurchases.php?action=chItem&value="+encodeURIComponent(str)+"&id="+str1,true);

	xmlhttp2.send();
}

function formSubmit(status)
{
	
	if(ch(status)!=0){
		document.getElementById("status").value=status;
		document.getElementById("frm1").submit();
	}
}
</script>

<link
	href="css/style.css" rel="stylesheet" type="text/css" />
<link
	href="calendar/calendar.css" rel="stylesheet" type="text/css" />


<div class="title"></div>
<form method="post" action="newform-handle.php" id="frm1"   name="f13">
	<input type="hidden" name='type' value="<?=$type?>" />
	<input type="hidden" name='action' value="<?=$action?>" />
	<input type="hidden" name='status' id="status"/>
	<input type="hidden" name='id' value="<?=$id?>" />

	<div class="main_content" style="min-height: 895px;position:relative;" >
		<ul class="top_but">
			<li>
			<?php if($action=="my_declined" || $action=="my_sending"){?>
				<a href="mydocument-list-mydocument-saved-content"><img src="images/back.png" alt="" /> </a>
			<?php }else{?>
				
			<?php if(isset($_REQUEST['page'])){?>
				<?php if($action=='forward'){?>
				<a href="mydocument-list-mydocument-approved-content&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /> </a>
				<?php }else{?>
				<a href="<?=$url[0]?>&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /> </a>
				<?php }?>
			<?php }else{?>
				<a href="<?=$url[0]?>"><img src="images/back.png" alt="" /> </a>
			<?php } 
			} ?>
			
			
				<p class="hidden" >
				<?=$l_back?>
				</p>
			</li>
			<li><input type="button" name="Save" value="" id="save"   onclick="formSubmit('Save')"
				style="background: url(images/save.png) no-repeat; width: 36px; height: 36px; border: none; position: absolute; top:0px; left:0px; right:0px; bottom:0px; margin: auto" />
				<p class="hidden">
				<?=$l_save?>
				</p></li>
			<li><input type="button" name="Send" value="" id="send" onclick="formSubmit('Send')"
				style="background: url(images/send.png) no-repeat; width: 36px; height: 36px; border: none; position: absolute; top:0px; left:0px; right:0px; bottom:0px; margin: auto" />
				<p class="hidden" >
				<?=$l_send_document?>
				</p></li>
			<?php 
			
				if($_REQUEST['action']){
					if($_REQUEST['action']=="editform" || $_REQUEST['action']=="my_declined"){
						?>
						
						<li><input type="button" name="Delete" value="" onclick="formSubmit('Delete')" id='delete'
						style="background: url(images/deny.png) no-repeat; width: 36px; height: 36px; border: none; position: absolute; top:0px; left:0px; right:0px; bottom:0px; margin: auto" />
						<p class="hidden">
						<?=$l_delete?>
						</p></li>
						
						<?php 
					}
				}
			
			
			?>
		</ul>
		<table class="tcontent" cellpadding="5" cellspacing="0">
			<tr>
				<td width="15%" class="col_left"><?php echo $l_title?></td>
				<td  colspan="3"><input type="text" id="title" onkeypress ="return focusOnMyInputBox(event,'content1');" name="title" value="<?php echo $ftitle?>"
					style="height: 24px; width: 100%; border: 1px solid #c4c0c9;line-height: 24px;" /></td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?php echo $l_content?></td>
				<td colspan="3"><textarea rows="3" cols="5" id="content1"  name="content1" 
						style="width: 100%; border: 1px solid #c4c0c9"><?php echo $fcontent?></textarea></td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?php echo  $l_purchase_date?></td>
				<td style="text-align: left"><?php
				$myCalendar1 = new tc_calendar("date1", true);
				$myCalendar1->setIcon("calendar/images/iconCalendar.gif");
				$d=split('-',$fromdate,3);
					
				$myCalendar1->setDate($d[2],$d[1],$d[0]);
				$myCalendar1->setPath("calendar/");
				$myCalendar1->setYearInterval(2010, 2015);
				$myCalendar1->dateAllow('2010-01-01', '2015-12-31');
				//$myCalendar1->setHeight(350);
				//$myCalendar1->autoSubmit(true, "form1");
				//$myCalendar1->setSpecificDate(array("2011-04-01", "2011-04-13", "2011-04-25"), 0, 'month');
				$myCalendar1->setOnChange("myChanged('test')");
				//$myCalendar->rtl = true;
				$myCalendar1->writeScript();
					
				//echo $myCalendar1->getDate();

				?></td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?php echo  $l_purpose?></td>
				<td colspan="3"><input type="text" id="purpose" name="purpose" onkeypress ="return focusOnMyInputBox(event,'project');" value="<?php echo $fpurpose?>"
					style="height: 24px; width: 100%; border: 1px solid #c4c0c9;line-height: 24px;" /></td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?php echo $l_project?></td>
				<td colspan="3"><input type="text" id="project" name="project" onkeypress ="return focusOnMyInputBox(event,'description');" value="<?php echo $fproject?>" 
					style="height: 24px; width: 100%; border: 1px solid #c4c0c9;line-height: 24px;" /></td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?php echo $l_description?></td>
				<td colspan="3"><textarea rows="3" cols="5" id="description"  name="description" 
						style="width: 100%; border: 1px solid #c4c0c9"><?php echo $fdescription?></textarea></td>
			</tr>
		</table>
		
		<div style='npadding-top:2px;margin-left:20px'>
						  <?php include 'attach/attach.php';?>
						  </div>	
		
		
		<div style="padding-top: 20px; ">
			<input type="button" style="width:24px;height:24px;" value="+" class="btnupbg btnupload" name="plus" onclick="addCompany()"  /> 
			<input type="button" style="width:24px;height:24px;" value="-" class="btnupbg btnupload " name="sub" onclick="delCompany()"  />
		</div>
		
		<div id="company">
		
		<?php 
		
			$temp=-1;
			$k=1;
			$c=0;
			$total=0;
			foreach ($listpurchase as $purchase){
				
			if($temp!=$purchase[7]){
				$temp=$purchase[7];
	
			$c=$purchase[7];
			?>
			
			
		<table id="themcongty" >
			<tr>
				<td style="padding-top: 5px;">
					<div class="btn_cong">
					<?php if($purchase[8]==0){?>
						<input type="checkbox" onclick="checkCompany(<?=$c?>)" />
						<?php }else{?>
						<input type="checkbox" checked="checked" onclick="checkCompany(<?=$c?>)" />
						<?php }?>
					<span>&nbsp;&nbsp;<b><?php echo $l_company_name." :"?></b>&nbsp;</span>
					</div>
				</td>
				<td >
					<div id="customerbox" >
					<div style="float:left">
						<input onkeypress="return focusOnMyInputBox(event,'name<?=$k?>');" onchange="chCompany(this.value,<?=$c?>)" onkeyup="chCompany(this.value,<?=$c?>)" type="text" size="30" value="<?=$purchase[2]?>" name="companyname[]" id="<?echo "inputString".$c;?>"  style="height: 24px; width: 300px; border: 1px solid #c4c0c9;font-size: 12px;line-height: 24px;" autocomplete="off" />
						<div class="suggestionsBox" id="suggestions" style="display:none;">
							<img src="images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
							<div class="suggestionList" id="autoSuggestionsList">
								&nbsp;
							</div>
						</div> 						
					</div>
					<div style=" float:left; position:relative; margin-top: 5px; margin-left: -21px">
						<img alt="" src="images/arrow-down.png" id="<?echo "menu_expand".$c;?>" >
					    <div id="<?echo "content_menu_expand".$c;?>" class="passul content_menu_expand" style="display:none">
					        <ul>
					        <?php 
					        
					    		$sql="select ac_customer.CustomerName from ac_customer where ac_customer.Activest=1";
								$result = mysql_query($sql);
								if($result)
								{
									$i=0;
									while($row=mysql_fetch_array($result))
									{
										?>
										<li onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'" onclick="clickCustomer('<?=$row['CustomerName']?>','<?=$c?>')" 
											<?php 
												if($i%2!=0){
													?>
													class="bgkhac"
													<?php 
												}
											?>
										> <?php echo $row['CustomerName'];?></li>
										<?php 
										$i++;
									}
								}
					    	?>
					        </ul>
					    </div>
					</div>
					</div>
				</td>
			</tr>
		</table>
		
		<div id="purchase">
		<table class="tcontent" cellpadding="5" cellspacing="0" id="tblView">
			<tr class="trtit">
				<td width="4%">
					<div style="width: 62px;margin-right: -10px;">
						<input type="button" style="width:24px;height:24px;" value="+" class="btnupbg btnupload" name="plus" id="btnAddMore" onclick="addPurchase(<?=$c?>)" /> 
						<input type="button" style="width:24px;height:24px;" value="-" class="btnupbg btnupload " name="sub" onclick="delPurchase(<?=$c?>)" />
					</div>
				</td>
				<td width="3%"><?php echo $l_no?></td>
				<td width="32%"><?php echo $l_product_item?></td>
				<!--  <td width="30%"><?php //echo $l_company_name?></td> -->
				<td width="8%"><?php echo $l_quantity?></td>
				<td width="8%"><?php echo $l_price?></td>
				<td width="8%"><?php echo $l_price_vat?></td>
				<td width="8%"><?php echo $l_total_amount?></td>
			</tr>
			<?php }
		
			
				
				?>
				<tr class="my_row">
					<?php  if($purchase[0]==0){?>
					<td><input type="checkbox"  onclick="checkPurchase(<?=$k?>)" /></td>
					<?php }else{?>
					<td><input type="checkbox" checked="checked"  onclick="checkPurchase(<?=$k?>)" /></td>
					<?php }?>
					<td><?=$k."-".$c?></td>
					
					<td><input type="hidden"  name="company[]" value="<?=$purchase[7]?>"/><input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'0')" onchange="chItemPurchase(this.value,<?=$k?>)" onkeyup="chItemPurchase(this.value,<?=$k?>)" id="<?echo "name".$k?>" name="productitem[]"   style="height: 24px; width: 96%; border: 1px solid #c4c0c9;line-height: 24px;" value="<?=$purchase[1]?>" /></td>
					<td><input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'1')" onchange="chQuantityPurchase(this.value,<?=$k?>)" onkeyup="chQuantityPurchase(this.value,<?=$k?>)" id="<?echo "txtNumber".$k?>" name="quantity[]" style="height: 24px; width: 96%; border: 1px solid #c4c0c9;line-height: 24px;"	value="<?=$purchase[3]?>" autocomplete="off"  /></td>
					<td><div id='<?echo "price".$k;?>'><input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'1')" onchange="chPricePurchase(this.value,<?=$k?>)"   onkeyup="chPricePurchase(this.value,<?=$k?>)"  id="<?echo "txtPrice".$k?>" name="price[]"  style="height: 24px; width: 96%; border: 1px solid #c4c0c9;line-height: 24px;"	value="<?=number_format($purchase[4])?>"  autocomplete="off"  /></div></td>
					<td><div id='<?echo "vat".$k;?>'><input onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'1')" onchange="chVatPurchase(this.value,<?=$k?>)" onkeyup="chVatPurchase(this.value,<?=$k?>)" id="<?echo "txtVat".$k?>" type="text" name="pricevat[]"    style="height: 24px; width: 96%; border: 1px solid #c4c0c9;line-height: 24px;"  value="<?=number_format($purchase[5])?>" autocomplete="off"  /></div></td>
					<td><div id='<?echo "total".$k;?>'><input type="text" name="totalamount[]" style="height: 24px; width: 96%; border: 1px solid #c4c0c9;line-height: 24px;"  value="<?=number_format($purchase[6])?>" readonly="readonly" /></div></td>
				</tr>
				<?php 
				$total=$total+$purchase[6];
				$k++;
				}?>
			
		</table>
		
		
		
		</div>
		<input type="hidden" id="count"  value="<?=$soct?>"/>
		<table class="tcontent" cellpadding="5" cellspacing="0" style="margin-top: 10px">
			<tr>
				<td width="20%" class="col_left"><?php echo $l_total_amount;?></td>
				<td style="text-align: left">
					<div id='all'><input type="text" readonly="readonly"  name="alltotalamount" value="<?=number_format($total)?>" style="height: 24px; width: 30%; border: 1px solid #c4c0c9" /></div>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?php echo $l_comment?></td>
				<td><textarea rows="3" cols="5" name="comment" id="comment"
						style="width: 100%; border: 1px solid #c4c0c9"><?php echo $fcomment?></textarea></td>
			</tr>
		</table>
		</div>
	</div>
	
</form>
<div style="diplay:none">
						 <?php include 'attach/attachhidden.php';?>
				</div>